#!/usr/bin/env python
# -*- coding: UTF-8 -*-
"""
@Project ：employment_class 
@File    ：03_tLogin.py
@IDE     ：PyCharm 
@Author  ：小邓的烂笔头
@Date    ：2021/10/17 下午4:38 
"""

from hashlib import sha1
from pymysql import *

name = input('请输入用户名：')
pwd = input('请输入密码：')
sha = sha1(pwd.encode('utf-8'))
ensrypts = sha.hexdigest()

sql = 'select passwd from users where name=%s'


class MySqlHelper(object):
    def __init__(self):
        self.connect = connect(
            host='localhost',
            port=3306,
            user='root',
            password='123456',
            db='base'
        )
        self.cursorl = self.connect.cursor()

    def close(self):
        self.cursorl.close()
        self.connect.close()

    def cud(self, sql, params):
        try:
            self.cursorl.execute(sql, params)
            result = self.cursorl.fetchall()
            self.connect.commit()
            return result
        except Exception as e:
            print(e)
        finally:
            self.close()

    def login(self):
        data = self.cud(sql,[name])
        if len(data) == 0 :
            print("账号输入有误！")
        elif data[0][0] != ensrypts:
            print('输入的密码有误')
        elif data[0][0] == ensrypts:
            print('登录成功')
        else:
            print("。。")

if __name__ == '__main__':
    name = [name]
    print(MySqlHelper().login())
